﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>客户管理</title>
    <#include "../common/link.ftl"/>

</head>
<script>
    $(function () {




        $(".btn-input").click(function () {
            //清空表单数据
            $("#editForm input").val('');
            //找到绑定这个事件的标签,获取这个标签的data前缀,json为后缀的属性的值
            var json = $(this).data('json');
            //数据回显
            if(json){
                $('#editForm input[name="id"]').val(json.id);
                $('#editForm input[name="name"]').val(json.name)
                $('#editForm input[name="age"]').val(json.age);
                $('#editForm select[name="gender"]').val(json.gender);
                $('#editForm input[name="tel"]').val(json.tel);
                $('#editForm input[name="qq"]').val(json.qq);
                $('#editForm select[name="job.id"]').val(json.jobId);
                $('#editForm select[name="source.id"]').val(json.sourceId);

                //标题改为编辑
                $('#myModalLabel').html("编辑操作")
            }else{
                $('#myModalLabel').html("新增操作")
            }
            //弹出模态框
            $('#customerModal').modal('show');
        })

        //保存按钮进行的操作
        $(".customerSubmitBtn").click(function () {
            //将表单转为异步请求,并且马上提交请求
            $("#editForm").ajaxSubmit(function (data) {
                $.messager.confirm("温馨提示",data.msg,function () {
                    window.location.reload();
                })
            });
        });



        //客户跟进历史新增模态框
        //给客户跟进历史按钮绑定事件
        $(".btn-traceHistory").click(function () {
            var json = $(this).data('json');
            $('#traceForm input[name="customer.id"]').val(json.id);
            $('#customerName').val(json.name);
            //弹出模态框
            $('#traceModal').modal('show');
        });
        //给客户跟进历史模态框按钮的绑定事件,提交表单
        $(".traceSubmitBtn").click(function () {
            //将表单转化为异步请求,并且马上提交请求
            $("#traceForm").ajaxSubmit(function (data) {
                $.messager.confirm("温馨提示",data.msg,function () {
                    window.location.reload();
                });
            })
        });

        //给日期增加格式
        $('.datepicker').datepicker({
            language: 'zh-CN',
            autoclose: true,
            todayHighlight: true, // 今天时间高亮
            format: 'yyyy-mm-dd',
            endDate:new Date() // 今天之后的日期都不可以选择
        });


        //弹出客户状态模态框
        $(".btn-status").click(function () {
            var json = $(this).data('json');
            $('#statusForm input[name="cid"]').val(json.id);
            $('#statusForm input[name="name"]').val(json.name);
            //弹出模态框
            $('#statusModal').modal('show');
        });

        //给客户跟进历史模态框按钮的绑定事件,提交表单
        $(".statusSubmitBtn").click(function () {
            //将表单转化为异步请求,并且马上提交请求
            $("#statusForm").ajaxSubmit(function (data) {
                $.messager.confirm("温馨提示",data.msg,function () {
                    window.location.reload();
                });
            })
        });
    });

</script>


<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl"/>
    <#--<c:set var="currentMenu" value="customer"/>-->
    <!--菜单回显-->
    <#assign currentMenu = "customer_potential">
    <#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>客户管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/customer/potentialList.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入姓名/邮箱">
                    </div>
                    <@shiro.hasAnyRoles name="admin,Market_Manger">
                        <label for="keyword">市场专员:</label>
                        <select id="seller" name="sellerId" class="form-control">
                            <option value="-1">请选择</option>
                            <#list sellers as seller>
                                <option value="${seller.id}" <#if qo.sellerId == seller.id>selected</#if>>${seller.name}</option>
                            </#list>
                        </select>
                    </@shiro.hasAnyRoles>
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <@shiro.hasPermission name="customer:saveOrUpdate">
                        <a class="btn btn-success btn-input" style="margin: 10px">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </@shiro.hasPermission>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>客户名称</th>
                            <th>年龄</th>
                            <th>性别</th>
                            <th>电话</th>
                            <th>qq</th>
                            <th>工作</th>
                            <th>来源</th>
                            <th>销售员</th>
                            <th>录入人</th>
                            <th>录入时间</th>
                            <th>客户状态</th>
                            <th>操作</th>
                        </tr>
                            <#list pageResult.list as customer>
                            <tr>
                                <td>${customer_index + 1}</td>
                                <td>${customer.name}</td>
                                <td>${customer.age}</td>
                                <td>
                                    <#if customer.gender==0>女</#if>
                                    <#if customer.gender==1>男</#if>
                                </td>
                                <td>${customer.tel}</td>
                                <td>${customer.qq}</td>
                                <td>${(customer.job.title)!}</td>
                                <td>${(customer.source.title)!}</td>
                                <td>${(customer.seller.name)!}</td>
                                <td>${(customer.inputUser.name)!}</td>
                                <td>${customer.inputTime?string('yyyy-MM-dd')}</td>
                                <td>${(customer.statusName)!}</td>
                                <td>
                                    <a data-json='${customer.json}'
                                       class="btn btn-info btn-xs btn-input">
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a data-json='${customer.json}'
                                       class="btn btn-info btn-xs btn-traceHistory">
                                        <span class="glyphicon glyphicon-pencil"></span> 客户跟进历史
                                    </a>
                                    <a data-json='${customer.json}'
                                       class="btn btn-info btn-xs btn-status">
                                        <span class="glyphicon glyphicon-pencil"></span> 客户状态
                                    </a>
                                </td>
                            </tr>
                            </#list>
                    </table>
                    <#include "../common/page.ftl"/>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl"/>
</div>

<#--客户新增/编辑模态框-->
<#-- 编辑客户模态框 -->
<div class="modal fade" id="customerModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">客户新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" placeholder="请输入客户姓名"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">年龄：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="age" placeholder="请输入客户年龄"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">性别：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="gender">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">电话：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="tel" placeholder="请输入客户电话"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">QQ：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control"name="qq" placeholder="请输入客户QQ"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">职业：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="job.id">
                                <#list jobs as j>
                                    <option value="${j.id}">${j.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">来源：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="source.id">
                                <#list sources as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary customerSubmitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<#-- 跟进历史 -->
<div class="modal fade" id="traceModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">跟进历史</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customerTraceHistory/saveOrUpdate.do" method="post" id="traceForm">
                    <input type="hidden" name="customer.id" value=""/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" id="customerName" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进时间：</label>
                        <div class="col-lg-6">
                            <input type="date" class="form-control datepicker" name="traceTime"
                                   placeholder="请输入跟进时间"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进记录：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" name="traceDetail"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">交流方式：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceType.id">
                                <#list types as t>
                                    <option value="${t.id}">${t.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进结果：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceResult.id">
                                <#list traceResult as tr>
                                    <option value="${tr.id}">${tr.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">备注：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" name="remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary traceSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<#-- 修改客户状态 -->
<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">修改客户状态</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customer/updateStatus.do" method="post" id="statusForm">
                    <input type="hidden" name="cid" value=""/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">客户状态：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="status">
                                <option value="0">潜在客户</option>
                                <option value="1">客户池</option>
                                <option value="2">开发失败</option>
                                <option value="3">流失</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary statusSubmitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
